/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projekt.zaliczeniowy.tkunit.runner.TestOrderStrategy;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import projekt.zaliczeniowy.tkunit.test.Test;

/**
 *
 * @author Tomek
 */
public abstract class SimpleTestIteratorTemplateMethodAdapter implements Iterator<Test>{
    
    protected int currentIndex;
    protected boolean hasMoreElements;
    final protected List<Test> testsToMahshall;

    public SimpleTestIteratorTemplateMethodAdapter(List<Test> tests){
        this.currentIndex = -1;
        this.hasMoreElements = tests != null && tests.size() > 0;
        this.testsToMahshall = Collections.unmodifiableList(tests);
    }

    public synchronized boolean hasNext() {
        return hasMoreElements;
    }

    /*
     * Template Method!!!
     */
    public synchronized Test next() {
        Test test = null;
        if (hasMoreElements) {
            test = testsToMahshall.get(currentIndex);
            currentIndex++;
            if (currentIndex >= testsToMahshall.size()) {
                hasMoreElements = false;
            }
        } else {
            throw new Error("There is no more test!!! You didn't use the iterator properly");
        }
        return test;
    }

    public synchronized void remove() {
        throw new Error("Don't modify the test list!!!"); //To change body of generated methods, choose Tools | Templates.
    }

    public Iterator<Test> iterator() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
